<template>
	<view class="mainpadding2">
		<view class="mainpadding_top flexbetween radius ffffff">
			<view class="sanshier fonweight xiaohei">售后类型</view>
			<view class="flexright">
				<u-radio-group v-model="type" placement="row" circle>
					<u-radio activeColor="#1ba95b" :customStyle="{marginRight: '30rpx'}" label="仅退款"
						name="0"></u-radio>
					<u-radio activeColor="#1ba95b" label="退货退款" name="1"></u-radio>
				</u-radio-group>
			</view>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="sanshier fonweight xiaohei">退款说明</view>
			<textarea placeholder="请输入退款说明" class="margin_top" style="width: 100%;height: 200rpx;" v-model="reason"></textarea>
			<view class="flexleft flex_wrap">
				<view class="shilitu margin_top margin_right2 dingwei" v-for="(item,index) in images_text" :key="index">
					<image :src="item" mode=""></image>
					<view class="shanchu" @click="delindex(index,images_text,images)">
						<u-icon name="close-circle-fill"></u-icon>
					</view>
				</view>
				<view class="margin_top shangc margin_right2" v-if="images.length<5"
					@click="uploadImg(5,images,images_text)">
					<image src="../static/image/system/shangchuan.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="submit()">提交申请</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				images: [],
				images_text: [],
				reason: "",
				listid:"",
				goods_id:"",
				type:"0",
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.goods_id = options.goods_id
		},
		methods: {
			submit(){
				if(this.reason==""){
					httpRequest.toast("请输入退款说明")
					return false
				}
				httpRequest.request('/api/scoregoods/addApply', 'POST', {
					order_goods_id:this.goods_id,
					order_id:this.listid,
					type:this.type,
					reason:this.reason,
					images:this.images.join(),
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
			uploadImg(value, upImgs, upImgs_text) { //上传图片
				let _this = this;
				let num = 0
				if (value == 5) {
					num = Number(value) - upImgs.length;
					if (num <= 0) {
						return false;
					}
				} else {
					num = 1
				}
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			delindex(index, upImg, upImgs_text) {
				upImg.splice(index, 1)
				upImgs_text.splice(index, 1)
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					upImg.push(res.url)
					upImgs_text.push(image_item);
				}).catch(err => {});
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f9f9f9;
	}

	.shangc {
		width: 160rpx;
		height: 160rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.shanchu {
		position: absolute;
		top: -10rpx;
		right: -10rpx;
	}

	.shanchu2 {
		position: absolute;
		bottom: -10rpx;
		right: -50%;
		transform: translate(0, -50%);
	}

	.shilitu {
		width: 160rpx;
		height: 160rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>